﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using CVSS.Client.CIQS.Entity.StatPeccancy;
using CVSS.Client.CIQS.UI;
using SysCommon.Business.CVSS.WS.BaseData;
using SysCommon.Business.CVSS.WS.Stat;
//using SysCommon.Entity.Business.Stat;
using SysCommon.Entity.CVSS.WS.Stat;
using SysCommon.Entity.CVSS.WS.BaseData;
using SysCommon.Tools;
using CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy;
using CVSS.Client.CIQS.Data;

using CarMemberPeccancyStat_Ety=SysCommon.Entity.CVSS.WS.Stat.CarMemberPeccancyStat_Ety;

namespace CVSS.Client.CIQS.UI
{
    public class CarMemberPeccancyStatFormMDT
    {
        private CarMemberPeccancyStatForm frm=new CarMemberPeccancyStatForm();
        //private SysCommon.Entity.CVSS.WS.Stat.CarMemberPeccancyStat_Ety[] m_etys;
        //SysCommon.UI.DataGridViewForPageCtrl dataGridViewForPageCtrl1;

        public CarMemberPeccancyStatFormMDT()
        {
        }

        #region ShowForm()函数
        public bool ShowForm()
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的Show函数");
                //事件声明
                //
                //加载窗体
                frm.Load += new EventHandler(frm_Load);
                frm.ShowDialog();

                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的Show函数结束");

                return true;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的Show函数出错", ex);
            }
            return false;
        }

        void frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ExcelData.QuitExcelHandler();
        }

        string ExcelData_QuitExcel()
        {
            //ExcelData.QuitExcelHandler();
            try
            {
                System.Windows.Forms.SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "(*.xls)|*.xls";
                string strSaveFile = "";
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    strSaveFile = saveFileDialog.FileName;
                }
                //ExcelData.QuitExcelHandler();
                return strSaveFile;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用ExcelData_QuitExcel()出错", ex);
                return "";
            }
        }

        #endregion

        #region 显示数据
        private void ShowDataView(object [] etys)
        {
            try
            {
                frm.dvp_DataView.dg_DataView.DataSource = null;
                SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety ety = new View_Statisticunitp_Ety();
                //ety.CARMEMBERNAME; ety.CARTYPENAME; ety.PECCANCYNUM; ety.PECCANCYRAT;ety.PECCANCYTYPENAME
                string[] cnColumns = new string[] { "所在车队","违章类型","车辆类型","违章数量","违章率"};
                string[] enColumns = new string[] { "CARMEMBERNAME","PECCANCYTYPENAME","CARTYPENAME","PECCANCYNUM","PECCANCYRAT"};
                ShowEntityForDataGridView.SetDefaultDataGrigStyle(frm.dvp_DataView.dg_DataView);

                ShowEntityForDataGridView.EntityToView(cnColumns, enColumns, etys, frm.dvp_DataView.dg_DataView);

                frm.dvp_DataView.dg_DataView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            }
            catch(Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用ShowDataView出错", ex);
            }
        }
        #endregion

        #region 获取统计信息
        SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety[] GetStatInfo(
            SysCommon.Entity.CVSS.WS.Stat.PeccancyCondition_Ety query)
        {
            try
            {
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws=new WS_Stat_BizCtrlImpl();
                SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety[] etys = ws.CarMemberPeccancyStat(query);
                return etys;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用GetStatInfo(SysCommon.Entity.CVSS.WS.Stat.QueryCondition_Ety query)出错", ex);
            }
            return null;
        }
        #endregion

        #region 获取统计信息(webservice压缩处理)
        /// <summary>
        ///  获取统计信息(webservice压缩处理)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] GetStatInfo2(PeccancyCondition_Ety query)
        {
            try
            {
                WS_Stat_BizCtrlImpl ws = new WS_Stat_BizCtrlImpl();
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys = null;
                byte[] zipBuffer = ws.CarMemberPeccancyStat2(query);
                etys = (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);
                return etys;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("GetStatInfo2(PeccancyCondition_Ety query)出错",ex);
            }
            return null;
        }
        #endregion

        #region webservice压缩分页
        /// <summary>
        /// webservice压缩分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] GetStatInfoWithCompressForPage(PeccancyCondition_Ety query)
        {
            try
            {
                int pageIndex = 1;
                int pageSize = 30;
                WS_Stat_BizCtrlImpl ws = new WS_Stat_BizCtrlImpl();
                
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys = null;
                byte[] zipBuffer = ws.CarMemberPeccancyStatWithCompressForPage(query,pageIndex,pageSize);
                object obj = null;
                if (zipBuffer != null)
                {
                   obj = SysCommon.Tools.CompressionHelper.DeCompressEntity(zipBuffer);
                   InitDataGridView();
                }
                    SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety> result = obj
                    as SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety>;

                    string[] cnColumns = new string[] { "所在车队", "违章类型", "车辆类型", "违章数量", "违章率" };
                    string[] enColumns = new string[] { "CARMEMBERNAME", "PECCANCYTYPENAME", "CARTYPENAME", "PECCANCYNUM", "PECCANCYRAT" };

                    if (result != null)
                    {
                        frm.dvp_DataView.Init(pageIndex, result.PageCount, pageSize, result.Objects,cnColumns ,enColumns );

                    }
                    else
                    {
                    //SysCommon.Entity.Business.Stat.View.View_Statisticunita_Ety[] etys =
                    //    new SysCommon.Entity.Business.Stat.View.View_Statisticunita_Ety[0];
                        frm.dvp_DataView.Init(0, 0, 0, etys,  cnColumns,enColumns);
                    }
                 return etys;
                }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("GetStatInfoWithCompressForPage(PeccancyCondition_Ety query)出错", ex);
            }
            return null;
        }

        #region InitDataGridView
        /// <summary>
        /// 初始化DataGridView
        /// </summary>
        void InitDataGridView()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys =
                    new SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[0];
                if (etys == null) return;
                string[] cn_col = new string[] { "所在车队", "违章类型", "车辆类型", "违章数量", "违章率" };
                string[] en_col = new string[] { "CARMEMBERNAME", "PECCANCYTYPENAME", "CARTYPENAME", "PECCANCYNUM", "PECCANCYRAT" };


                SysCommon.Tools.ShowEntityForDataGridView.SetDefaultDataGrigStyle(frm.dvp_DataView.dg_DataView);
                SysCommon.Tools.ShowEntityForDataGridView.EntityToView(cn_col, en_col, etys, frm.dvp_DataView.dg_DataView);
                frm.dvp_DataView.dg_DataView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CVSS.Client.CIQS.UI.InitDataGridView出错", ex);
            }
        }
        #endregion


        #region  dvp_DataView_OnDataChangedHandlerEvent
        /// <summary>
        /// 数据改变时的处理函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">当前页面数据参数</param>
        /// <returns>新数据</returns> 
        object dvp_DataView_OnDataChangedHandlerEvent(object sender, SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandlerEventArgs e)
        {
            int pageIndex = e.PageIndex;
            int countPerPage = e.PageSize;
            int pageSize = e.PageSize;
            SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载数据，请稍候...");
            System.Windows.Forms.Application.DoEvents();
            WS_Stat_BizCtrlImpl ws = new WS_Stat_BizCtrlImpl();
            PeccancyCondition_Ety query = new PeccancyCondition_Ety();

             query.BEGINTIME = frm.dtp_FromDate.Value;
                query.ENDTIME = frm.dtp_ToDate.Value;
                query.CARMEMBER = frm.cmb_CarMember.Text;
                query.CARTYPE = frm.cmb_CarType.Text;
                query.PECCANCYTYPE = frm.cmb_PeccancyType.Text;

                if (query.CARMEMBER == "全部") query.CARMEMBER = "";
                if (query.CARTYPE == "全部") query.CARTYPE = "";
                if (query.PECCANCYTYPE == "全部") query.PECCANCYTYPE = "";

            byte[] zipBuffer = ws.CarMemberPeccancyStatWithCompressForPage(query, pageIndex, pageSize);

            object obj = null;
            if (zipBuffer != null)
            {
                obj = SysCommon.Tools.CompressionHelper.DeCompressEntity(zipBuffer);
                InitDataGridView();
            }
            SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety> result = obj
                as SysCommon.Entity.Business.CompressResult_Ety<SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety>;

            if (result != null)
            {
                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
                return result.Objects;
            }
            return null;

        }
        #endregion

        #endregion

        #region 窗体事件响应函数
        #region 
        /// <summary>
        /// 统计方法调用
        /// </summary>
        void Stat()
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_Start_Click函数");
                frm.btn_Start.Enabled = false;
                SysCommon.Entity.CVSS.WS.Stat.PeccancyCondition_Ety filter = new SysCommon.Entity.CVSS.WS.Stat.PeccancyCondition_Ety();

                filter.BEGINTIME = frm.dtp_FromDate.Value;
                filter.ENDTIME = frm.dtp_ToDate.Value;
                filter.CARMEMBER = frm.cmb_CarMember.Text;
                filter.CARTYPE = frm.cmb_CarType.Text;
                filter.PECCANCYTYPE = frm.cmb_PeccancyType.Text;

                if (filter.CARMEMBER == "全部") filter.CARMEMBER = "";
                if (filter.CARTYPE == "全部") filter.CARTYPE = "";
                if (filter.PECCANCYTYPE == "全部") filter.PECCANCYTYPE = "";

                //SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety[] etys = GetStatInfo(filter);//备份
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys = GetStatInfoWithCompressForPage(filter);//webservice压缩分页
                #region 备份
                //if(etys==null)
                //{
                //    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有找到符合条件的结果", false);
                //    frm.btn_Start.Enabled = true;
                //    return;
                //}

                //ShowDataView(etys);
                #endregion
                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_Start_Click函数结束");
                frm.btn_Start.Enabled = true;
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_Return_Click函数出错", ex);
            }
        }
        #endregion

        #region 开始统计
        /// <summary>
        /// 开始统计
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btn_Start_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载数据，请稍候...");
                System.Windows.Forms.Application.DoEvents();
                Stat();
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] m_Etys = (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[])frm.dvp_DataView.dg_DataView.DataSource;

                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
                if (m_Etys == null || m_Etys.Length == 0)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有找到符合条件的结果", false);
                }
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用btn_Query_Click(object sender, EventArgs e)出错", ex);
            }
        }
        #endregion

        #region 导出到Excel
        void btn_ExportToExcel_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数");

                frm.btn_ExportToExcel.Enabled = false;
                Export();
                frm.btn_ExportToExcel.Enabled = true;

                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数结束");
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_ExportToExcel_Click函数出错", ex);
            }
        }
        #endregion

        #region 打印
        void btn_Print_Click(object sender, EventArgs e)
        {
            try
            {
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的btn_Print_Click函数");
                frm.btn_Print.Enabled = false;
                //PrintPageEventArgs e=new PrintPageEventArgs();
                Print();
                //Business.PrintDataGridView.Print(frm.dg_DataView,true,null,ref x,ref y);
                frm.btn_Print.Enabled = true;
                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的btn_Print_Click函数结束");
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的btn_Print_Click函数出错", ex);
            }
        }
        #endregion

        #region 加载窗体

        void frm_Load(object sender, EventArgs e)
        {
            try
            {
                SysCommon.MsgBox.ProecssingMessageBox.StartProecssing(this.frm, "正在加载窗体，请稍候...");
                System.Windows.Forms.Application.DoEvents();
                SysCommon.Global.mainLog.Debug("开始调用CarMemberPeccancyStatForm的frm_Load函数");
                frm.cmb_PeccancyType.Text = "全部";
                frm.cmb_CarType.Text = "全部";
                //
                //打印
                frm.btn_Print.Click += new EventHandler(btn_Print_Click);
                //
                //导出Excel表
                frm.btn_ExportToExcel.Click += new EventHandler(btn_ExportToExcel_Click);
                //
                //开始统计
                frm.btn_Start.Click += new EventHandler(btn_Start_Click);
                //
                //ExcelData.QuitExcel += new QuitExcelEventHandler(ExcelData_QuitExcel);
                //
                frm.FormClosing += new FormClosingEventHandler(frm_FormClosing);
                frm.dvp_DataView.OnDataChangedHandlerEvent += new SysCommon.UI.DataGridViewForPageCtrl.OnDataChangedHandler(dvp_DataView_OnDataChangedHandlerEvent);
                InitDataGridView();
                //InitCarMember(frm.cmb_CarMember);
                InitCarMember2(frm.cmb_CarMember);

                InitPeccancyType(frm.cmb_PeccancyType);
                InitCarType(frm.cmb_CarType);
                InitDataView();
                //InitDataView2();
                SysCommon.Global.mainLog.Debug("调用CarMemberPeccancyStatForm的frm_Load函数结束");
             
                SysCommon.MsgBox.ProecssingMessageBox.EndProecssing();
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用CarMemberPeccancyStatForm的frm_Load函数出错", ex);
            }
        }
        #endregion

        #endregion

        #region 打印
        void Print()
        {
            SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys = (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[])frm.dvp_DataView.dg_DataView.DataSource;
            if (etys == null)
            {
                SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要打印的数据", false);
                return;
            }
            if (etys.Length == 0)
            {
                SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要打印的数据", false);
                return;
            }
            //统计信息
            string carmembernames = "";
            //Dictionary<string, Result_Ety> results = new Dictionary<string, Result_Ety>();
            System.Collections.Hashtable results = new System.Collections.Hashtable();
            string tmpname = "";
            foreach (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety ety in etys)
            {
                CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety re_ety =
                    new CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety();
                tmpname = ety.CARMEMBERNAME;
                if (results.ContainsKey(tmpname))
                {
                    re_ety = (CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety)results[tmpname];
                    CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety pe = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                    switch (ety.CARTYPE)
                    {
                        case "1":
                            if (null == re_ety.CarType.Bus)
                            {
                                re_ety.CarType.Bus = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                re_ety.CarType.Bus.OverLoad = pe.OverLoad;
                                re_ety.CarType.Bus.OverSpeed = pe.OverSpeed;
                                re_ety.CarType.Bus.Tiredness = pe.Tiredness;
                                re_ety.CarType.Bus.Overline = pe.Overline;
                                re_ety.CarType.Bus.SeriousOverSpeed = pe.SeriousOverSpeed;
                            }
                            else
                            {
                                re_ety.CarType.Bus.OverLoad += pe.OverLoad;
                                re_ety.CarType.Bus.OverSpeed += pe.OverSpeed;
                                re_ety.CarType.Bus.Tiredness += pe.Tiredness;
                                re_ety.CarType.Bus.Overline += pe.Overline;
                                re_ety.CarType.Bus.SeriousOverSpeed += pe.SeriousOverSpeed;
                            }

                            break;
                        case "3":
                            if (null == re_ety.CarType.Car)
                            {
                                re_ety.CarType.Car = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();

                                re_ety.CarType.Car.OverLoad = pe.OverLoad;
                                re_ety.CarType.Car.OverSpeed = pe.OverSpeed;
                                re_ety.CarType.Car.Tiredness = pe.Tiredness;
                                re_ety.CarType.Car.Overline = pe.Overline;
                                re_ety.CarType.Car.SeriousOverSpeed = pe.SeriousOverSpeed;
                            }
                            else
                            {
                                re_ety.CarType.Car.OverLoad += pe.OverLoad;
                                re_ety.CarType.Car.OverSpeed += pe.OverSpeed;
                                re_ety.CarType.Car.Tiredness += pe.Tiredness;
                                re_ety.CarType.Car.Overline += pe.Overline;
                                re_ety.CarType.Car.SeriousOverSpeed += pe.SeriousOverSpeed;
                            }

                            break;
                        case "2":
                            if (null == re_ety.CarType.Truck)
                            {
                                re_ety.CarType.Truck = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                re_ety.CarType.Truck.OverLoad += pe.OverLoad;
                                re_ety.CarType.Truck.OverSpeed += pe.OverSpeed;
                                re_ety.CarType.Truck.Tiredness += pe.Tiredness;
                                re_ety.CarType.Truck.Overline += pe.Overline;
                                re_ety.CarType.Truck.SeriousOverSpeed += pe.SeriousOverSpeed;
                            }
                            else
                            {
                                re_ety.CarType.Truck.OverLoad += pe.OverLoad;
                                re_ety.CarType.Truck.OverSpeed += pe.OverSpeed;
                                re_ety.CarType.Truck.Tiredness += pe.Tiredness;
                                re_ety.CarType.Truck.Overline += pe.Overline;
                                re_ety.CarType.Truck.SeriousOverSpeed += pe.SeriousOverSpeed;
                            }

                            break;
                        case "5":
                            if (null == re_ety.CarType.Danger)
                            {
                                re_ety.CarType.Danger = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                re_ety.CarType.Danger.OverLoad = pe.OverLoad;
                                re_ety.CarType.Danger.OverSpeed = pe.OverSpeed;
                                re_ety.CarType.Danger.Tiredness = pe.Tiredness;
                                re_ety.CarType.Danger.Overline = pe.Overline;
                                re_ety.CarType.Danger.SeriousOverSpeed = pe.SeriousOverSpeed;
                            }
                            else
                            {
                                re_ety.CarType.Danger.OverLoad += pe.OverLoad;
                                re_ety.CarType.Danger.OverSpeed += pe.OverSpeed;
                                re_ety.CarType.Danger.Tiredness += pe.Tiredness;
                                re_ety.CarType.Danger.Overline += pe.Overline;
                                re_ety.CarType.Danger.SeriousOverSpeed += pe.SeriousOverSpeed;
                            }

                            break;
                    }
                    results[tmpname] = re_ety;
                }
                else
                {
                    carmembernames += tmpname + ",";
                    re_ety.StatTypeName = tmpname;
                    re_ety.CarType = new CarType_Ety();
                    switch (ety.CARTYPE)
                    {
                        case "1":
                            re_ety.CarType.Bus = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                            break;
                        case "3":
                            re_ety.CarType.Car = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                            break;
                        case "2":
                            re_ety.CarType.Truck = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                            break;
                        case "5":
                            re_ety.CarType.Danger = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                            break;
                    }
                    results.Add(tmpname, re_ety);
                }
            }
            carmembernames = carmembernames.Substring(0, carmembernames.Length - 1);
            string[] carmemberArray = carmembernames.Split(',');
            string path = Application.StartupPath + @"\Resource\ReportsTemplate\广东省车辆违章信息统计报表（车队管理）.xls";
            DateTime[] datetime = new DateTime[2];
            datetime[0] = frm.dtp_FromDate.Value;
            datetime[1] = frm.dtp_ToDate.Value;
            ExcelData.PrintStatPeccancyData(path, results, carmemberArray, datetime);
        }

        void Export()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys = (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[])frm.dvp_DataView.dg_DataView.DataSource;
                if (etys == null)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要导出的数据", false);
                    return;
                }
                if (etys.Length == 0)
                {
                    SysCommon.MsgBox.SysMessageBox.ShowInfoMessageBox(frm, "对不起，没有要导出的数据", false);
                    return;
                }
                //统计信息            
                string carmembernames = "";
                //Dictionary<string, Result_Ety> results = new Dictionary<string, Result_Ety>();
                System.Collections.Hashtable results = new System.Collections.Hashtable();

                string tmpname = "";
                foreach (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety ety in etys)
                {
                    CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety re_ety =
                        new CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety();

                    tmpname = ety.CARMEMBERNAME;
                    if (results.ContainsKey(tmpname))
                    {
                        re_ety = (CVSS.Client.CIQS.Entity.Stat.Peccancy.Result_Ety)results[tmpname];
                        CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety pe = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                        switch (ety.CARTYPE)
                        {
                            case "1":
                                if (null == re_ety.CarType.Bus)
                                {
                                    re_ety.CarType.Bus = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                    re_ety.CarType.Bus.OverLoad = pe.OverLoad;
                                    re_ety.CarType.Bus.OverSpeed = pe.OverSpeed;
                                    re_ety.CarType.Bus.Tiredness = pe.Tiredness;
                                    re_ety.CarType.Bus.Overline = pe.Overline;
                                    re_ety.CarType.Bus.SeriousOverSpeed = pe.SeriousOverSpeed;
                                }
                                else
                                {
                                    re_ety.CarType.Bus.OverLoad += pe.OverLoad;
                                    re_ety.CarType.Bus.OverSpeed += pe.OverSpeed;
                                    re_ety.CarType.Bus.Tiredness += pe.Tiredness;
                                    re_ety.CarType.Bus.Overline += pe.Overline;
                                    re_ety.CarType.Bus.SeriousOverSpeed += pe.SeriousOverSpeed;
                                }
                                
                                break;
                            case "3":
                                if (null == re_ety.CarType.Car)
                                {
                                    re_ety.CarType.Car = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();

                                    re_ety.CarType.Car.OverLoad = pe.OverLoad;
                                    re_ety.CarType.Car.OverSpeed = pe.OverSpeed;
                                    re_ety.CarType.Car.Tiredness = pe.Tiredness;
                                    re_ety.CarType.Car.Overline = pe.Overline;
                                    re_ety.CarType.Car.SeriousOverSpeed = pe.SeriousOverSpeed;
                                }
                                else
                                {
                                    re_ety.CarType.Car.OverLoad += pe.OverLoad;
                                    re_ety.CarType.Car.OverSpeed += pe.OverSpeed;
                                    re_ety.CarType.Car.Tiredness += pe.Tiredness;
                                    re_ety.CarType.Car.Overline += pe.Overline;
                                    re_ety.CarType.Car.SeriousOverSpeed += pe.SeriousOverSpeed;
                                }
                                
                                break;
                            case "2":
                                if (null == re_ety.CarType.Truck)
                                {
                                    re_ety.CarType.Truck = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                    re_ety.CarType.Truck.OverLoad += pe.OverLoad;
                                    re_ety.CarType.Truck.OverSpeed += pe.OverSpeed;
                                    re_ety.CarType.Truck.Tiredness += pe.Tiredness;
                                    re_ety.CarType.Truck.Overline += pe.Overline;
                                    re_ety.CarType.Truck.SeriousOverSpeed += pe.SeriousOverSpeed;
                                }
                                else
                                {
                                    re_ety.CarType.Truck.OverLoad += pe.OverLoad;
                                    re_ety.CarType.Truck.OverSpeed += pe.OverSpeed;
                                    re_ety.CarType.Truck.Tiredness += pe.Tiredness;
                                    re_ety.CarType.Truck.Overline += pe.Overline;
                                    re_ety.CarType.Truck.SeriousOverSpeed += pe.SeriousOverSpeed;
                                }
                                
                                break;
                            case "5":
                                if (null == re_ety.CarType.Danger)
                                {
                                    re_ety.CarType.Danger = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
                                    re_ety.CarType.Danger.OverLoad = pe.OverLoad;
                                    re_ety.CarType.Danger.OverSpeed = pe.OverSpeed;
                                    re_ety.CarType.Danger.Tiredness = pe.Tiredness;
                                    re_ety.CarType.Danger.Overline = pe.Overline;
                                    re_ety.CarType.Danger.SeriousOverSpeed = pe.SeriousOverSpeed;
                                }
                                else
                                {
                                    re_ety.CarType.Danger.OverLoad += pe.OverLoad;
                                    re_ety.CarType.Danger.OverSpeed += pe.OverSpeed;
                                    re_ety.CarType.Danger.Tiredness += pe.Tiredness;
                                    re_ety.CarType.Danger.Overline += pe.Overline;
                                    re_ety.CarType.Danger.SeriousOverSpeed += pe.SeriousOverSpeed;
                                }
                                
                                break;
                        }
                        results[tmpname] = re_ety;
                    }
                    else
                    {
                        carmembernames += tmpname + ",";
                        re_ety.StatTypeName = tmpname;
                        re_ety.CarType = new CarType_Ety();
                        switch (ety.CARTYPE)
                        {
                            case "1":
                                re_ety.CarType.Bus = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                                break;
                            case "3":
                                re_ety.CarType.Car = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                                break;
                            case "2":
                                re_ety.CarType.Truck = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                                break;
                            case "5":
                                re_ety.CarType.Danger = GetPeccancy(ety.PECCANCYTYPE, ety.PECCANCYNUM);
                                break;
                        }
                        results.Add(tmpname, re_ety);
                    }
                }
                carmembernames = carmembernames.Substring(0, carmembernames.Length - 1);
                string[] carmemberArray = carmembernames.Split(',');

                string path = Application.StartupPath + @"\Resource\ReportsTemplate\广东省车辆违章信息统计报表（车队管理）.xls";
                DateTime[] datetime = new DateTime[2];
                datetime[0] = frm.dtp_FromDate.Value;
                datetime[1] = frm.dtp_ToDate.Value;

                ExcelData.ExportStatPeccancyData(path, results, carmemberArray, datetime);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用Export()出错", ex);
            }
        }

        CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety GetPeccancy(string peccancyType, int number)
        {
            CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety ety = new CVSS.Client.CIQS.Entity.Stat.BaseEntity.Peccancy.Peccancy_Ety();
            switch (peccancyType)
            {
                case "1":
                    ety.OverSpeed = number;
                    break;
                case "2":
                    ety.OverLoad = number;
                    break;
                case "3":
                    ety.Tiredness = number;
                    break;
                case "4":
                    ety.SeriousOverSpeed = number;
                    break;
                case "5":
                    ety.Overline = number;
                    break;
            }
            return ety;
        }
        #endregion

        #region 界面初始化
        /// <summary>
        /// 界面初始化
        /// </summary>
        /// <param name="m_ComboBox"></param>
        void InitCarMember(System.Windows.Forms.ComboBox m_ComboBox)
        {
            m_ComboBox.Items.Clear();
            WS_BaseData_BizCtrlImpl m_ws = new WS_BaseData_BizCtrlImpl();
            CarMember_Ety[] m_Etys = m_ws.GetAllCarMemberInfo();
            m_ComboBox.Items.Add("全部");
            foreach (CarMember_Ety ety in m_Etys)
            {
                if (ety.NAME == null) continue;
                m_ComboBox.Items.Add(ety.NAME);
            }
            m_ComboBox.Text = "全部";
        }

        #region InitCarMember2()(webservice压缩处理)
        /// <summary>
        /// InitCarMember2()(webservice压缩处理)
        /// </summary>
        /// <param name="m_ComboBox"></param>
        void InitCarMember2(System.Windows.Forms.ComboBox m_ComboBox)
        {
            SysCommon.Entity.Human.CarMember_Ety[] m_Etys=null;
            m_ComboBox.Items.Clear();
            WS_BaseData_BizCtrlImpl m_ws = new WS_BaseData_BizCtrlImpl();
            byte[] zipBuffer= m_ws.GetAllCarMemberInfo2();
            m_Etys = (SysCommon.Entity.Human.CarMember_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);
            m_ComboBox.Items.Add("全部");
            foreach (SysCommon.Entity.Human.CarMember_Ety ety in m_Etys)
            {
                if (ety.NAME == null) continue;
                m_ComboBox.Items.Add(ety.NAME);
            }
            m_ComboBox.Text = "全部";
        }
        #endregion
        void InitPeccancyType(System.Windows.Forms.ComboBox m_ComboBox)
        {
            GetSystemSettings("PeccancyType",m_ComboBox);
            
        }

        void InitCarType(System.Windows.Forms.ComboBox m_ComboBox)
        {
            GetSystemSettings("VehicleType",m_ComboBox);
        }

        void GetSystemSettings(string name, System.Windows.Forms.ComboBox m_ComboBox)
        {
            m_ComboBox.Items.Clear();
            WS_BaseData_BizCtrlImpl m_ws = new WS_BaseData_BizCtrlImpl();
            SysSetting_Ety[] etys = m_ws.SearchSysSettingInfo1(name);
            m_ComboBox.Items.Add("全部");
            foreach (SysSetting_Ety ety in etys)
            {
                if (ety.DISPLAYVALUE == "全部") continue;
                m_ComboBox.Items.Add(ety.DISPLAYVALUE);
            }
            if (m_ComboBox.Items.Count > 0)
            {
                m_ComboBox.SelectedIndex = 0;
            }
            m_ComboBox.Text = "全部";
        }

        void InitDataView()
        {
            try
            {
                SysCommon.Entity.CVSS.WS.Stat.PeccancyCondition_Ety filter = new SysCommon.Entity.CVSS.WS.Stat.PeccancyCondition_Ety();
                SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl ws = new SysCommon.Business.CVSS.WS.Stat.WS_Stat_BizCtrlImpl();

                filter.CARMEMBER = "";
                filter.CARTYPE = "";
                filter.BEGINTIME = System.DateTime.Now.AddDays(-1);
                filter.ENDTIME = System.DateTime.Now;

                SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety[] etys = ws.CarMemberPeccancyStat(filter);
                if (etys == null)
                {
                    etys = new SysCommon.Entity.CVSS.WS.Stat.View_Statisticunitp_Ety[0];
                }
                //ShowDataView(etys);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用InitDataView()出错！", ex);
            }
        }
        #region InitDataView2()(webservice压缩处理)
        /// <summary>
        /// InitDataView2()(webservice压缩处理)
        /// </summary>
        void InitDataView2()
        {
            try
            {
                SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[] etys=null;
                PeccancyCondition_Ety filter = new PeccancyCondition_Ety();
                WS_Stat_BizCtrlImpl ws = new WS_Stat_BizCtrlImpl();

                filter.CARMEMBER = "";
                filter.CARTYPE = "";
                filter.BEGINTIME = System.DateTime.Now.AddDays(-1);
                filter.ENDTIME = System.DateTime.Now;

                byte[] zipBuffer= ws.CarMemberPeccancyStat2(filter);
                etys = (SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[])CompressionHelper.DeCompressEntity(zipBuffer);
                if (etys == null)
                {
                    etys = new SysCommon.Entity.Business.Stat.View.View_Statisticunitp_Ety[0];
                }
                //ShowDataView(etys);
            }
            catch (Exception ex)
            {
                SysCommon.Global.mainLog.Error("调用InitDataView()出错！", ex);
            }
        }
        #endregion


        #endregion

    }
}
